package users

import (
	"api/internal/respons"
	"context"
	"user_srv/userclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUpdateLogic {
	return &UserUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 用户资料修改
func (l *UserUpdateLogic) UserUpdate(req *types.UserUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.UserRpc.UserUpdate(l.ctx, &userclient.UserUpdateRequest{
		Id:       req.Id,
		NickName: req.NickName,
		ImageCur: req.ImageCur,
		Gender:   req.Gender,
		Age:      req.Age,
		Email:    req.Email,
		Mobile:   req.Mobile,
	})
	if err != nil {
		return respons.Error(400, "服务端错误", err.Error()), err
	}
	return respons.Success(update), nil

}
